/****************************************************************************
** Copyright (C) 2017 ZhouLiQiu(zhouliqiu@126.com).
**
** This file is part of the qtc_astyle, It is a plugin for Qt Creator.
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
** THE SOFTWARE.
**
****************************************************************************/
#ifndef ASTYLEACTIONS_H
#define ASTYLEACTIONS_H

#include "valueaction.h"

#include <QHash>
#include <QObject>
#include <QString>
#include <QVariant>
#include <QSettings>

namespace AStyle {
namespace Internal {

enum AStyleSettingsCode
{
    Style,

    Tab_IndentWithSpace,
    Tab_IndentWithTab,
    Tab_ForceTab,
    Tab_ChangeSpacePerTab,
    Tab_SpacePerTab,
    Tab_SpacePerIndent,
    Tab_AttachNamespace,
    Tab_AttachClass,
    Tab_AttachInline,
    Tab_AttachExtren,

    Indent_ClassBlocks,
    Indent_AccessModifiers,
    Indent_SwitchBlocks,
    Indent_CaseBlocks,
    Indent_Namespaces,
    Indent_Labels,
    Indent_Predefine,
    Indent_PreCon,
    Indent_ColumnOne,
    Indent_Min,
    Indent_MinEnable,
    Indent_Max,
    Indent_MaxEnable,

    Pad_BreakHeader,
    Pad_BreakAll,
    Pad_Operator,
    Pad_ParensOutside,
    Pad_ParensInside,
    Pad_FirstParenOutside,
    Pad_Header,
    Pad_Unpad,
    Pad_Delete,
    Pad_Fill,
    Pad_AlignPointer_Enable,
    Pad_AlignPointer,
    Pad_AlignRef_Enable,
    Pad_AlignRef,

    Format_BreakClosing,
    Format_BreakElseIf,
    Format_AddBracket,
    Format_AddOneBracket,
    Format_RemoveBracket,
    Format_KeepOneLineBlocks,
    Format_KeepOneLineStatement,
    Format_ConvertTab,
    Format_CloseTemplate,
    Format_RemoveCommentPrefix,
    Format_MaxCodeLen,
    Format_MaxCodeLenEnable,
    Format_BreakAfterLogic
};

class AStyleSettings : public QObject
{
    Q_OBJECT

public:
    AStyleSettings();
    ~AStyleSettings();
    void insertItem(int code, ValueAction *item,
                    const QString &longname = QString(),
                    const QString &shortname = QString());

    ValueAction *item(int code);
    ValueAction *item(const QString &name);

    void readSettings(QSettings *settings);
    void writeSettings(QSettings *settings);

    QString getAsArguments();

private:
    QHash<int, ValueAction *> m_items;
    QHash<QString, int> m_nameToCode;
    QHash<int, QString> m_codeToName;

    QString m_strStyle;
    void appendArg(QString str);
};

AStyleSettings *theAStyleSettings();
ValueAction *theAStyleSetting(int code);

} // namespace Internal
} // namespace AStyle
#endif // ASTYLEACTIONS_H
